<?php
class EncryptionHandler
{
	
	private static $o_instance;
	protected $s_defaultEncryptionKey;
	
	private function __construct()
	{
		//$this->s_defaultEncryptionKey = hash('md5', Claycode_configuration::getInstance()->getEncryptionKey());
		$this->s_defaultEncryptionKey = SessionHandler::getInstance()->getSessVarKey();
	}
	
	public static function get()
	{
		if(!isset(self::$o_instance) ||  self::$o_instance == null){
			self::$o_instance = new EncryptionHandler();
		}
		return self::$o_instance;
	}
	
	function doEncrypt($data) {
		return rtrim(strtr(base64_encode($this->s_defaultEncryptionKey . $data), '+/', '-_'), '=');
	}
	
	function doDecrypt($data) {
		$raw = base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
		return str_replace($this->s_defaultEncryptionKey, '', $raw);
	}
	
}